﻿using System;
public abstract class Shape
{
    public abstract double Area { get; }
    public abstract bool IsValid { get; }
}

public class Rectangle : Shape
{
    public double Length { get; }
    public double Width { get; }

    public Rectangle(double length, double width)
    {
        Length = length;
        Width = width;
    }

    public override double Area => Length * Width;
    public override bool IsValid => Length > 0 && Width > 0;
}

public class Square : Shape
{
    public double Side { get; }

    public Square(double side)
    {
        Side = side;
    }

    public override double Area => Side * Side;
    public override bool IsValid => Side > 0;
}

public class Circle : Shape
{
    public double Radius { get; }

    public Circle(double radius)
    {
        Radius = radius;
    }

    public override double Area => Math.PI * Radius * Radius;
    public override bool IsValid => Radius > 0;
}
internal class Program
{
    static void Main(string[] args)
    {
        Random random = new Random();
        Shape[] shapes = new Shape[10];
        double totalArea = 0;

        for (int i = 0; i < shapes.Length; i++)
        {
            switch (random.Next(3))
            {
                case 0:
                    shapes[i] = new Rectangle(random.NextDouble() * 10, random.NextDouble() * 10);
                    break;
                case 1:
                    shapes[i] = new Square(random.NextDouble() * 10);
                    break;
                case 2:
                    shapes[i] = new Circle(random.NextDouble() * 10);
                    break;
            }
            if (shapes[i].IsValid)
            {
                totalArea += shapes[i].Area;
                Console.WriteLine("第"+i+"个 Shape area:" + shapes[i].Area);
            }
        }    

        Console.WriteLine("Total area:"+ totalArea);
    }
}




